# -*- coding: utf-8 -*-

import cherrypy
import commonlib
import simplejson as json

class DownloadImageService():
    
    @cherrypy.expose
    def index(self):
        return 'download image service'
    
    def download(self, url, path, prefix=''):
        filename = ''
        try:
            filename = commonlib.downloadImage(url, path, prefix)
        finally:
            return json.dumps({'filename': filename})
        
if __name__ == '__main__':
    
    global_conf = {
        'global': {
        'server.socket_host': '27.0.12.109',
        'server.socket_port': 8891,
        'tools.encode.on': True,
        'tools.encode.encoding': 'UTF-8',
        'tools.gzip.on': True
        },
    }
    cherrypy.config.update(global_conf)
    cherrypy.quickstart(DownloadImageService())
